﻿Imports Data

Public Class Menu
    Private Property nombre As String
    Public Property id_usuario As String

    Private Sub SalirToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Try
            Application.Exit()
        Catch ex As Exception

        End Try
    End Sub



    Private Sub MarcaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MarcaToolStripMenuItem.Click
        Try
            Dim marca As New MarcaForm
            marca.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub MantenedorToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MantenedorToolStripMenuItem.Click

    End Sub

    Private Sub IngresarPagosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)

    End Sub


    Private Sub PagosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PagosToolStripMenuItem.Click
        Try
           
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ActualizacionToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ActualizacionToolStripMenuItem.Click

    End Sub

    Private Sub MenuStrip1_ItemClicked(sender As System.Object, e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub AboutToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        Try
            Dim about As New About
            about.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub BancoToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles BancoToolStripMenuItem.Click
        Try
            Dim banco As New Banco
            banco.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub EmpleadosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EmpleadosToolStripMenuItem.Click
        Try
            Dim empleado As New EmpleadosForm
            empleado.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FormaDePagosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles FormaDePagosToolStripMenuItem.Click
        Try
            Dim formaPago As New FormaPagos
            formaPago.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub ModoDePagosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ModoDePagosToolStripMenuItem.Click
        Try
            Dim modoPago As New ModoPagos
            modoPago.Show()


        Catch ex As Exception

        End Try
    End Sub

    Private Sub ProveedoresToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ProveedoresToolStripMenuItem.Click
        Try
            Dim proveedores As New Proveedores
            proveedores.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub EstadosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EstadosToolStripMenuItem.Click
        Try
            Dim estado As New Estados
            estado.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub VerEstadisticasToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles VerEstadisticasToolStripMenuItem.Click
        Try
            Dim estadistica As New Estadisticas
            estadistica.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub MantenedorEntregasToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MantenedorEntregasToolStripMenuItem.Click
        Try
            Dim entrega As New Entregas
            entrega.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub IngresarFacturaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles IngresarFacturaToolStripMenuItem.Click
        Try
            Dim factura As New Facturas
            factura.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub ProductosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ProductosToolStripMenuItem.Click
        Try
            Dim stock As New Cantidades
            stock.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub OrdenesDeCompraToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OrdenesDeCompraToolStripMenuItem.Click
        Try
            Dim orden As New OrdenDeCompra
            orden.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub TipoProductoToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles TipoProductoToolStripMenuItem.Click
        Try
            Dim tipoProducto As New TipoProducto
            tipoProducto.Show()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub TareasToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles TareasToolStripMenuItem.Click
        Try
            Dim tareas As New TareasPendientes
            tareas.ShowDialog()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            Me.lblUsuario.Text = String.Format("Bienvenido {0}", nombre)
            Me.lblFecha.Text = String.Format("HOY ES: {0}/{1}/{2}", Date.Now.Day, Date.Now.Month, Date.Now.Year)

            Me.CargarTareasPendientes()

        Catch ex As Exception

        End Try
    End Sub

    Private Sub CargarTareasPendientes()
        Try
            Me.lvTareasPendiente.Items.Clear()
            Using db As New SerigraphicaDBDataContext
                Dim l_tareas = (From x In db.Tareas_Pendientes _
                                Where x.fecha_a_realizar > Date.Now _
                                Select New With {.nombre = x.nombre, _
                                             .descripcion = x.descripcion, _
                                             .fecha = x.fecha_a_realizar, _
                                             .estado = x.Estado.nombre, _
                                                 .id = x.id}).ToList


                Me.lvTareasPendiente.BeginUpdate()

                For Each item In l_tareas
                    Me.lvTareasPendiente.Items.Add(New ListViewItem(New String() {item.nombre, item.descripcion, item.fecha, item.estado}) With {.Name = item.id})
                Next


                Me.lvTareasPendiente.EndUpdate()
                Me.lvTareasPendiente.Refresh()
            End Using
        Catch ex As Exception

        End Try

    End Sub



    Public Sub New()
        InitializeComponent()
    End Sub


    Public Sub New(ByVal usuario As String, ByVal id As Integer)

        InitializeComponent()
        nombre = usuario
        Me.id_usuario = id
    End Sub

    Private Sub CatalogarTareaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CatalogarTareaToolStripMenuItem.Click
        Try
            Using db As New SerigraphicaDBDataContext
                Dim obj As Tareas_Pendientes = db.Tareas_Pendientes.Select(Function(p) p).Where(Function(p) p.id = lvTareasPendiente.SelectedItems(0).Name).FirstOrDefault
                Dim tareaPendiente As New CatalogarTarea(obj.id, obj.nombre, obj.descripcion, obj.Estado.nombre)
                tareaPendiente.ShowDialog()

                Me.CargarTareasPendientes()
            End Using
        Catch ex As Exception

        End Try
    End Sub


    Private Sub IngresarDeudasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IngresarDeudasToolStripMenuItem.Click
        Try
            Dim deuda As New Deudas(Me.id_usuario)
            deuda.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub EmpleadosToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles EmpleadosToolStripMenuItem1.Click
        Try
            Dim pagoDeudaEmpleado As New PagoEmpleado
            pagoDeudaEmpleado.Show()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ProveedorToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ProveedorToolStripMenuItem.Click
        Try
            Dim pagoDeudaProveedor As New PagoProveedor
            pagoDeudaProveedor.Show()
        Catch ex As Exception

        End Try
    End Sub
End Class